Skip to content

Conversation

@rkel
Copy link
Contributor

@rkel rkel commented Aug 7, 2025

Remove Generic Access Service implementation from gatt files and move it into separate file in services directory.
The proposed name is just gap_default as it is default implementation that may be switched off by the user in purpose of providing the GAP implementation directly in the application.

In the end it serves the same purpose that #93946 but gives the user total freedom of implementation when needed in the same time being 100% compatible with the current solution.

I was testing it manually and now I can enable and disable default GAP implementation.

The main reason of this PR is to discuss if we wish to go into this solution instead of #93946.

To be done:
[v] - GAP service validation during bt_enable.
[v] - review all configurations that need to be moved to Kconfig.gap_default
[v] - test of the functionality (BabbleSim)
[v] - sample with GAP reimplementation on App side
[ ] - update documentation

# Copyright (c) 2025 Koppel Electronic
# SPDX-License-Identifier: Apache-2.0

config BT_GAP_DEFAULT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config name is too generic. The GAP Service is only one component of GAP. I suggest something like BT_GAP_SVC_DEFAULT_IMPL.

help
Enable the default GATT Generic Access Service.
Enabled by default provides basic GAP functionality.
If disabled user can provide its own implementation in the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should say "must provide" and maybe "otherwise the system is not Bluetooth qualification compliant" or similar.

Copy link
Contributor Author

@rkel rkel Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started it from "must" but then I thought that not everybody cares about being qualification compliant. But the wording like:

If disabled, it is the application responsibility to provide its own implementation
of GAP service, otherwise the system is not Bluetooth qualification compliant.

Probably explains everything and not "forces" anybody to do anything - freedom :)

strlen(name));
}

#if defined(CONFIG_BT_DEVICE_NAME_GATT_WRITABLE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configs for the GAP Service should be moved Kconfig.gap_default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I am just wondering if it Kconfig.gap_default is good place for it. Maybe we should have Kconfig.gap - with all its configurations and then Kconfig.gap_default.

Comment on lines 111 to 123
/* This checks if the range entered is valid */
BUILD_ASSERT(!(CONFIG_BT_PERIPHERAL_PREF_MIN_INT > 3200 &&
CONFIG_BT_PERIPHERAL_PREF_MIN_INT < 0xffff));
BUILD_ASSERT(!(CONFIG_BT_PERIPHERAL_PREF_MAX_INT > 3200 &&
CONFIG_BT_PERIPHERAL_PREF_MAX_INT < 0xffff));
BUILD_ASSERT(!(CONFIG_BT_PERIPHERAL_PREF_TIMEOUT > 3200 &&
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT < 0xffff));
BUILD_ASSERT((CONFIG_BT_PERIPHERAL_PREF_MIN_INT == 0xffff) ||
(CONFIG_BT_PERIPHERAL_PREF_MIN_INT <=
CONFIG_BT_PERIPHERAL_PREF_MAX_INT));
BUILD_ASSERT((CONFIG_BT_PERIPHERAL_PREF_TIMEOUT * 4U) >
((1U + CONFIG_BT_PERIPHERAL_PREF_LATENCY) *
CONFIG_BT_PERIPHERAL_PREF_MAX_INT));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether this is not GAP Service specific or even GATT specific. They are used in conn.c. But on the other hand they are defined under "ATT and GATT options". There seems to be a mistake here one way or the other. @jhedberg, should we move these configs out of "ATT and GATT" into a generic GAP space?

It's clearly not right to have these assertions here while the configs are used in conn.c.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, seems like they should move to some GAP-specific place. Btw, some of those build asserts should probably be converted into range directives in Kconfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhedberg @alwa-nordic - should I just leave this assertions in the gatt.c for the purpose of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it right now - it looks little odd as now we have only the parameter checking in the gatt.c. But I get it that it is better not to move it to the module that may be disabled.

@alwa-nordic alwa-nordic requested a review from Copilot August 8, 2025 10:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extracts the Generic Access Service (GAP) implementation from the GATT core files into a separate, configurable service module. This allows users to disable the default GAP implementation and provide their own custom implementation when needed.

Key changes:

  • Creates a new configurable GAP service module in the services directory
  • Removes GAP implementation from the core GATT files
  • Maintains 100% compatibility with existing functionality through default enablement

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
subsys/bluetooth/services/gap_default.c New file containing the extracted GAP service implementation
subsys/bluetooth/services/Kconfig.gap_default Configuration file for the default GAP service
subsys/bluetooth/services/Kconfig Includes the new GAP configuration
subsys/bluetooth/services/CMakeLists.txt Builds the GAP service conditionally
subsys/bluetooth/host/gatt.c Removes the GAP service implementation
include/zephyr/bluetooth/gap.h Adds service name definition for consistency
Comments suppressed due to low confidence (1)


#if defined(CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE)
#define GAP_APPEARANCE_PROPS (BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE)
#if defined(CONFIG_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN)
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration macro name is inconsistent with the pattern used elsewhere. Should be CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN to match the naming convention.

Suggested change
#if defined(CONFIG_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN)
#if defined(CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN)

Copilot uses AI. Check for mistakes.
BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ |
#if defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_AUTHEN)
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration macro name is inconsistent with the pattern used elsewhere. Should be CONFIG_BT_DEVICE_NAME_GATT_WRITABLE_AUTHEN to match the naming convention.

Suggested change
#if defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_AUTHEN)
#if defined(CONFIG_BT_DEVICE_NAME_GATT_WRITABLE_AUTHEN)

Copilot uses AI. Check for mistakes.
BT_GATT_PERM_READ |
#if defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_AUTHEN)
BT_GATT_PERM_WRITE_AUTHEN,
#elif defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_ENCRYPT)
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration macro name is inconsistent with the pattern used elsewhere. Should be CONFIG_BT_DEVICE_NAME_GATT_WRITABLE_ENCRYPT to match the naming convention.

Suggested change
#elif defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_ENCRYPT)
#elif defined(CONFIG_BT_DEVICE_NAME_GATT_WRITABLE_ENCRYPT)

Copilot uses AI. Check for mistakes.
@rkel
Copy link
Contributor Author

rkel commented Aug 8, 2025

Can we please discuss now mainly if this is the way we wish to go? If yes - I will work on it little more before changing it into valid PR. Now it is rather proof of concept to discuss this vs #93946. I know we can implement both - but to be honest, any of this two just solves my issues. This one I think gives more freedom to the user, but requires (a little) more work from the application perspective if the user wants to overwrite default functionality.
I am saying "a little more" as you can always just copy default implementation, add any checking and application notification and call it a day.

@jhedberg
Copy link
Member

jhedberg commented Aug 8, 2025

Can we please discuss now mainly if this is the way we wish to go?

To me it sounds like a reasonable approach at least, i.e. have a default implementation which can be completely overridden by the app if it wants to.

@rkel rkel force-pushed the bt_gap_default_service branch 2 times, most recently from ace01bc to 38b4d8a Compare August 9, 2025 21:29
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 9, 2025

@Thalley
Copy link
Contributor

Thalley commented Aug 11, 2025

I generally like and approve of the idea that Zephyr provides a GAP service that works out of the box, similar to DIS, BAS, etc., and where users can choose to define and implement their own (similar to the other services).

2 things we need to consider for this approach is

  1. Unlike (most) other services, GAP service shall always be there on a Bluetooth devices (the only mandatory service IIRC).
  2. Unlike (most) other services, there shall only ever be a single GAP service on a device.

Both of the above can be verified at runtime, where we in bt_enable can verify that the service has been registered, as well as verifying in bt_gatt_service_register that no other service with BT_UUID_GAP has been registered.

@alwa-nordic alwa-nordic added the Bluetooth Review Discussion in the Bluetooth WG meeting required label Aug 14, 2025
@jhedberg
Copy link
Member

Discussed in the Bluetooth WG meeting. Consensus was to move the GAP service to subsys/bluetooth/services

@jhedberg jhedberg added area: Bluetooth and removed Bluetooth Review Discussion in the Bluetooth WG meeting required labels Aug 14, 2025
@rkel rkel force-pushed the bt_gap_default_service branch from 38b4d8a to 3214e90 Compare October 1, 2025 10:55
@rkel
Copy link
Contributor Author

rkel commented Oct 1, 2025

Just a rebase before any changes.

@rkel rkel force-pushed the bt_gap_default_service branch 3 times, most recently from 9689adc to 5c141cb Compare October 2, 2025 09:14
@jhedberg
Copy link
Member

jhedberg commented Oct 2, 2025

@rkel please be consistent with the commit subject prefix. Take a look at e.g. git log subsys/bluetooth and just use the same style as the majority of existing commits.

@rkel rkel force-pushed the bt_gap_default_service branch 2 times, most recently from 47420b3 to b34b4eb Compare October 2, 2025 11:05
@rkel
Copy link
Contributor Author

rkel commented Oct 2, 2025

@Thalley I had added some verification if there is exactly one GAP service in GATT database.

@rkel rkel force-pushed the bt_gap_default_service branch from cb3839c to b511a1e Compare October 3, 2025 05:56
@zephyrbot zephyrbot added area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Tests Issues related to a particular existing or missing test area: Samples Samples platform: nRF BSIM Nordic Semiconductors, nRF BabbleSim labels Dec 1, 2025
@rkel
Copy link
Contributor Author

rkel commented Dec 1, 2025

Please note that if #100235 would change before merging - the changes have to migrated to gap_default implementation. But it would not change the idea itself.

@rkel rkel force-pushed the bt_gap_default_service branch from ba2652a to ebf2cad Compare December 1, 2025 23:45
Copilot finished reviewing on behalf of rkel December 1, 2025 23:46
@zephyrbot zephyrbot requested a review from kartben December 1, 2025 23:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@rkel rkel force-pushed the bt_gap_default_service branch 2 times, most recently from ed5d850 to f9c379e Compare December 3, 2025 23:48
rkel added 6 commits December 4, 2025 09:45
Remove Generic Access Service implementation from gatt files and move it
into separate file in services directory.
The proposed name is just gap_default as it is default implementation
that may be switched off by the user in purpose of providing the GAP
implementation directly in the application.

Signed-off-by: Radosław Koppel <[email protected]>
…NULL

Set the unused argument of the name characteristic to NULL.
This removes the reference from GAP service to the hci_core.

Signed-off-by: Radosław Koppel <[email protected]>
Implement the validation if there is exactly one GAP service
in GATT database.
The validation is performed as soon as the GATT database
is available and forbids to enable the Bluetooth if the configuration
is not compatible with the Bluetooth Specification.
The verification may be disabled by the user for better performance
or deliberate implementation that is not compliant with the
specification.

Signed-off-by: Radosław Koppel <[email protected]>
Disable the GATT GAP service validation for the test.

Signed-off-by: Radosław Koppel <[email protected]>
The goal of this test is to ensure the default GAP Service can be disabled
and the application level GAP service implementation can be provided.

Signed-off-by: Radosław Koppel <[email protected]>
Adding a sample that presents how to implement non default GAP service
inside the application.

Signed-off-by: Radosław Koppel <[email protected]>
@rkel rkel force-pushed the bt_gap_default_service branch from f9c379e to c34bb12 Compare December 4, 2025 08:45
@rkel
Copy link
Contributor Author

rkel commented Dec 4, 2025

There are some kconfig options names that copilot yields about and it might have right here (see subsys/bluetooth/services/Kconfig.gap_svc). I marked them as resolved as this is direct copy of old settings and if we decide we should do anything about it I believe it should go to other PR.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 4, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth area: Samples Samples area: Tests Issues related to a particular existing or missing test platform: nRF BSIM Nordic Semiconductors, nRF BabbleSim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants